<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div>
    <div class="bgc" :style="backgroundStyle">
      <el-card class="box-card">
        <el-form class="box-box" ref="ruleFormRef" :rules="rules" :model="user">
          <img src="../image/7.webp" alt="" />
          <el-form-item class="input-flex" prop="username">
            <svg
              t="1699335859102"
              class="icon"
              viewBox="0 0 1024 1024"
              version="1.1"
              xmlns="http://www.w3.org/2000/svg"
              p-id="1485"
              width="48"
              height="48"
            >
              <path
                d="M756.829091 333.265455c0-134.981818-109.847273-244.829091-244.829091-244.829091S267.170909 198.283636 267.170909 333.265455c0 86.109091 45.149091 161.978182 112.64 205.730909-149.410909 54.458182-256.930909 197.352727-256.930909 365.847272 0 17.221818 13.963636 31.650909 31.185455 31.650909s31.185455-13.963636 31.185454-31.650909c0-180.130909 146.618182-326.283636 326.283636-326.283636 134.981818 0 244.829091-109.847273 244.829091-244.829091zM512 515.258182c-100.538182 0-181.992727-81.92-181.992727-181.992727S411.927273 151.272727 512 151.272727s181.992727 81.92 181.992727 181.992728-81.92 181.992727-181.992727 181.992727zM703.767273 565.527273a31.185455 31.185455 0 0 0-42.821818 11.636363 31.650909 31.650909 0 0 0 11.636363 42.821819 327.586909 327.586909 0 0 1 165.701818 284.392727c0 17.221818 13.963636 31.650909 31.185455 31.650909s31.650909-13.963636 31.650909-31.650909c0-140.101818-75.869091-269.963636-197.352727-338.850909z"
                fill="#409eff"
                p-id="1486"
              ></path>
            </svg>
            <el-input
              class="input-class"
              v-model="user.username"
              placeholder="请输入用户名"
              :prefix-icon="Search"
              clearable
            />
          </el-form-item>
          <el-form-item class="input-flex" prop="password">
            <svg
              t="1699335887536"
              class="icon"
              viewBox="0 0 1024 1024"
              version="1.1"
              xmlns="http://www.w3.org/2000/svg"
              p-id="1630"
              width="48"
              height="48"
            >
              <path
                d="M749.381818 387.723636h-25.134545V300.683636c0-117.294545-95.418182-212.712727-212.712728-212.712727S298.356364 183.389091 298.356364 300.683636v87.04H274.618182c-67.025455 0-121.483636 54.458182-121.483637 121.483637v305.338182c0 67.025455 54.458182 121.483636 121.483637 121.483636h474.763636c67.025455 0 121.483636-54.458182 121.483637-121.483636v-305.338182c0-67.025455-54.458182-121.483636-121.483637-121.483637zM361.192727 300.683636c0-82.850909 67.490909-149.876364 149.876364-149.876363s149.876364 67.490909 149.876364 149.876363v87.04H361.192727V300.683636z m446.836364 513.861819c0 32.581818-26.530909 58.647273-58.647273 58.647272H274.618182c-32.581818 0-58.647273-26.530909-58.647273-58.647272v-305.338182c0-32.581818 26.530909-58.647273 58.647273-58.647273h474.763636c32.581818 0 58.647273 26.530909 58.647273 58.647273v305.338182z"
                fill="#409eff"
                p-id="1631"
              ></path>
              <path
                d="M512 546.443636c-17.221818 0-31.650909 13.963636-31.650909 31.650909v131.258182c0 17.221818 13.963636 31.650909 31.650909 31.650909s31.185455-13.963636 31.185455-31.650909v-131.258182c0-17.221818-13.963636-31.650909-31.185455-31.650909z"
                fill="#409eff"
                p-id="1632"
              ></path>
            </svg>
            <el-input
              class="input-class"
              v-model="user.password"
              placeholder="请输入密码"
              :prefix-icon="Search"
              show-password
              clearable
            />
          </el-form-item>
          <el-form-item class="input-flex"></el-form-item>
          <el-form-item class="login-flex">
            <el-button
              style="width: 200px; height: 30px; background-color: #ffffff79; color: #000"
              @click="login"
              >登录</el-button
            >
          </el-form-item>
          <el-form-item class="input-flex">
            <p style="color: #000; cursor: pointer">忘记密码？</p>
            <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
            <p style="color: #000; cursor: pointer">注册账号</p>
          </el-form-item>
        </el-form>
      </el-card>
      <div class="dong-1"></div>
      <div class="dong-2"></div>
      <div class="dong-3"></div>
      <div class="dong-4"></div>
      <div class="dong-5"></div>
      <div class="dong-6"></div>
    </div>
  </div>
</template>

<script setup>
import { Search } from '@element-plus/icons-vue'
import { ref, computed, onBeforeUnmount } from 'vue'
import { useCounterStore } from '../stores/counter'
import router from '../router'
const userlogin = useCounterStore()
const ruleFormRef = ref()
const user = ref({
  username: '',
  password: ''
})
// 表单验证
const rules = ref({
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
    { min: 3, max: 5, message: '请输入3-5位用户名', trigger: 'blur' }
  ],
  password: [
    { required: true, message: '请输入用密码', trigger: 'blur' },
    { min: 3, max: 5, message: '请输入3-5位密码', trigger: 'blur' }
  ]
})

const login = async () => {
  if (!ruleFormRef.value) return
  await ruleFormRef.value.validate((valid, fields) => {
    if (valid) {
      userlogin.loginuser.username = user.value.username
      userlogin.loginuser.password = user.value.password
      router.push('/')
    } else {
      console.log('error submit!', fields)
    }
  })
}
// 背景色计算
const bgc = ref('')
const timer = setInterval(() => {
  bgc.value = (bgc.value + 1) % 360
}, 5000)
// 背景色赋值
const backgroundStyle = computed(() => {
  const hue = bgc.value
  return {
    background: `linear-gradient(to bottom, hsl(${hue}, 75%, 50%), hsl(${hue + 30}, 75%, 50%))`
  }
})
// 离开页面清楚定时器
onBeforeUnmount(() => {
  clearInterval(timer)
})
</script>

<style scoped>
.bgc {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.box-card {
  width: 480px;
  height: 480px;
  opacity: 0.8;
  background-color: rgba(250, 250, 250, 0.2);
  border-radius: 20px;
  box-shadow: 0 0 40px 10px #746d6db4;
  z-index: 3;
}
.box-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  position: relative;
}
.input-class {
  width: 300px;
  height: 40px;
}
.input-flex {
  height: 40px;
  display: flex;
  align-items: center;
}
.login-flex {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
img {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  opacity: 1;
}
::v-deep .el-card__body {
  padding: 20px 0 0 0;
}
::v-deep .el-card {
  border: 0;
}
::v-deep .el-input__wrapper {
  background-color: #ffffff00;
}
::v-deep .el-input__inner {
  color: #000000;
}
::v-deep .el-form-item__error {
  left: 20%;
}
.dong-1 {
  opacity: 0.4;
  width: 60px;
  height: 60px;
  position: absolute;
  top: 60%;
  left: 61%;
  box-shadow: 0 0 40px 10px #616161b4;
  background-color: rgba(250, 250, 250, 0.2);
  border-radius: 10px;
  animation: float 1.5s infinite linear alternate;
}
.dong-2 {
  opacity: 0.4;
  width: 75px;
  height: 75px;
  top: 80%;
  left: 80%;
  position: absolute;
  box-shadow: 0 0 40px 10px #746d6db4;
  background-color: rgba(250, 250, 250, 0.2);
  border-radius: 10px;
  animation: float 2s infinite linear alternate;
}
.dong-3 {
  opacity: 0.4;
  width: 100px;
  height: 100px;
  position: absolute;
  top: 70%;
  left: 25%;
  box-shadow: 0 0 40px 10px #746d6db4;
  background-color: rgba(250, 250, 250, 0.2);
  border-radius: 10px;
  animation: float 1s infinite linear alternate;
}
.dong-4 {
  opacity: 0.4;
  width: 50px;
  height: 50px;
  position: absolute;
  top: 10%;
  left: 15%;
  box-shadow: 0 0 40px 10px #746d6db4;
  background-color: rgba(250, 250, 250, 0.2);
  border-radius: 10px;
  animation: float 2s infinite linear alternate;
}
.dong-5 {
  opacity: 0.4;
  width: 200px;
  height: 200px;
  position: absolute;
  top: 28%;
  left: 28%;
  box-shadow: 0 0 40px 10px #746d6db4;
  background-color: rgba(250, 250, 250, 0.2);
  border-radius: 10px;
  animation: float 2.5s infinite linear alternate;
}
.dong-6 {
  opacity: 0.4;
  width: 250px;
  height: 250px;
  position: absolute;
  top: 5%;
  left: 70%;
  box-shadow: 0 0 40px 10px #746d6db4;
  background-color: rgba(250, 250, 250, 0.2);
  border-radius: 10px;
  animation: float 3s infinite linear alternate;
}
@keyframes float {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(30px);
  }
}
</style>
